#include <cstdio>
constexpr int MaxN = 1e3 + 5;
constexpr long long Mod = 1e9 + 7;
int n, k;
char s[MaxN];
char t[MaxN];
char a[MaxN];
char b[MaxN];
long long ca, cb;
long long answer;
void dfs(int u, int c, bool rev, long long temp)
{
    if (u == n)
    {
        if (ca <= temp && temp <= cb)
        {
            answer += temp;
            answer %= Mod;
        }
        return;
    }
    long long cp = temp;
    cp *= 2;
    if ((s[u] == 'R') ^ rev)
    {
        cp++;
    }
    cp %= Mod;
    dfs(u + 1, c, rev, cp);
    if (c >= 1)
    {
        rev = !rev;
        cp = temp;
        cp *= 2;
        if ((s[u] == 'R') ^ rev)
        {
            cp++;
        }
        cp %= Mod;
        dfs(u + 1, c - 1, rev, cp);
    }
}
bool check()
{
    for (int i = 1; i <= n; i++)
    {
        if (t[i] == a[i])
        {
            continue;
        }
        if (t[i] > a[i])
        {
            break;
        }
        else
        {
            return false;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (t[i] == b[i])
        {
            continue;
        }
        if (t[i] < b[i])
        {
            break;
        }
        else
        {
            return false;
        }
    }
    return true;
}
int main()
{
    freopen("lost.in", "r", stdin);
    freopen("lost.out", "w", stdout);
    scanf("%d%d", &n, &k);
    scanf("%s", s + 1);
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    if (k == 0)
    {
        t[1] = '1';
        for (int i = 1; i <= n - 1; i++)
        {
            t[i + 1] = s[i] == 'R' ? '1' : '0';
        }
        if (check())
        {
            long long temp = 0;
            for (int i = 1; i <= n; i++)
            {
                temp = (temp * 2 + (t[i] == '1' ? 1 : 0)) % Mod;
            }
            answer += temp;
        }
        for (int i = 1; i <= n - 1; i++)
        {
            t[i + 1] = s[i] == 'L' ? '1' : '0';
        }
        if (check())
        {
            long long temp = 0;
            for (int i = 1; i <= n; i++)
            {
                temp = (temp * 2 + (t[i] == '1' ? 1 : 0)) % Mod;
            }
            answer += temp;
        }
        printf("%lld\n", answer % Mod);
        return 0;
    }
    ca = 0;
    cb = 0;
    for (int i = 1; i <= n; i++)
    {
        ca = (ca * 2 + (a[i] == '1' ? 1 : 0)) % Mod;
    }
    for (int i = 1; i <= n; i++)
    {
        cb = (cb * 2 + (b[i] == '1' ? 1 : 0)) % Mod;
    }
    dfs(1, k, false, 1);
    printf("%lld\n", answer);
    return 0;
}